﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Developex.GenerateClassOnShema.Classes
{
	public class TableSettings : SimpleSettings
	{
		public string ClassName { get; set; }
		public string TableName { get; set; }

		public TableSettings(string tableName, string className)
		{
			ClassName = className;
			TableName = tableName;
			SectionsAllowedItemNames = new List<string>(Enum.GetNames(typeof(ColumnSettingsName)));
			GlobalSectionAllowedItemNames = new List<string>(Enum.GetNames(typeof(TableSettingsName)));
		}

		public bool ColumnSettingExists(string columnName, ColumnSettingsName settingName)
		{
			if (!Sections.ContainsKey(columnName))
				return false;
			return Sections[columnName].ContainsKey(settingName.ToString());
		}

		public string GetColumnSetting(string columnName, ColumnSettingsName settingName)
		{
			if (!ColumnSettingExists(columnName, settingName))
				return null;
			return Sections[columnName][settingName.ToString()];
		}

		public string GetColumnSetting(string columnName, ColumnSettingsName settingName, string defaultValue)
		{
			if (!ColumnSettingExists(columnName, settingName))
				return defaultValue;
			return Sections[columnName][settingName.ToString()];
		}

		public bool TableSettingExists(TableSettingsName settingName)
		{
			return GlobalSection.ContainsKey(settingName.ToString());
		}

		public string GetTableSetting(TableSettingsName settingName)
		{
			if (!TableSettingExists(settingName))
				return null;
			return GlobalSection[settingName.ToString()];
		}

		public string GetTableSetting(TableSettingsName settingName, string defaultValue)
		{
			if (!TableSettingExists(settingName))
				return defaultValue;
			return GlobalSection[settingName.ToString()];
		}
	}
}
